/*
 * Eugen Stoian <stoian.e@gmail.com> 2010
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

#ifndef PARAMETER_H
#define PARAMETER_H

#include <Object.h>
#include <Real.h>
#include <QString>
#include <Interval.h>
#include <QDataStream>
class Parameter:public Object
{
    Q_OBJECT
public:
    Parameter(const QString& name, const Interval& interval = Interval(0.0,1.0), int valuesCount = 11, QObject * parent = 0);

    virtual ~Parameter();

    Parameter& operator++();

    Parameter& operator--();

    Parameter& operator+=(double value);

    Parameter& operator-=(double value);

    Real value() const;

    bool isAuto() const;

    bool isFixed() const;

    void reset();
    
    const Interval &interval() const;

    Interval& interval();
    
    int valuesCount() const;
    
    const Real *data() const;
    
    bool isOutOfRange() const;
    
    double delta() const;

    virtual Object* clone() const;
    
    virtual bool isValid() const;
    
    virtual int type() const;

    friend QDataStream& operator<<(QDataStream& stream, const Parameter& parameter);

    friend QDataStream& operator>>(QDataStream& stream, Parameter& parameter);

    int index() const {
        return _index;
    }

signals:
    void changed();

    void valueChanged(double r);

public slots:
    void setValue(double value);

    void setAuto(bool ok);

    void setFixed(bool ok);

    void setValuesCount(int count);

    void setInterval(const Interval& interval);

protected:
    Interval _interval;
    bool _isAuto;
    QList<Real> _values;
    int _index;
    Real *_value;
    bool _outOfRange;
};

QDataStream& operator<<(QDataStream& stream, const Parameter& parameter);
QDataStream& operator>>(QDataStream& stream, Parameter& parameter);

#endif // PARAMETER_H
